a5_updateCRONLog Function
Syntax
Arguments
- projectGuidCharacter
The project GUID for the web project that owns the CRON job. Typically this is obtained by calling a5_getprojectguid().
- jobNameCharacter
The name of the CRON job as defined in the CRON Jobs editor (for example, the Job name field).
- runTimeTime
The date and time the job ran. Typically you pass now() so the current date and time are recorded in the log.
- statusCharacter
A short status string describing the outcome of the run, such as success or failed.
Returns
- ResultLogical
Returns .t. if the log entry was successfully written, or .f. if the log entry could not be written.
Description
Use a5_updateCRONLog() to add entries to the CRON Job Log system table when a CRON job runs. This helper function is typically called at the end of the .a5w page that implements the job to record whether it succeeded or failed.
Description
The a5_updateCRONLog() helper function updates the CRON Job Log system table for a CRON job run.
If a CRON job fails because of an Xbasic error, Alpha Anywhere automatically creates an entry in the CRON Job Log table. When a CRON job succeeds, you should call a5_updateCRONLog() from the .a5w page that implements the job to record the successful run (and any custom status text you want to use).
The CRON Job Log table is configured as a system table in Project Properties. If it does not already exist when you define your first CRON job, it is created automatically.
Example
The following example shows a .a5w page that generates a PDF report, emails it to a set of recipients, and then uses a5_updateCRONLog() to record whether the job completed successfully or failed.
<%a5
dim report as c = "report1.a5rpt"
dim fn as c = a5_default_path + chr(92) + report
dim reportfn as c = a5w_report_saveas(fn,"pdf")
dim ms as p
ms.message_html = "Here is your report"
ms.send_to = "person1@acme.com,person2@acme.com,person3@acme.com"
ms.subject = "Your report"
ms.from_alias = "AlphaSoftware"
ms.from_email = "noreply@alphasoftware.com"
ms.from_name = "AlphaSoftware"
ms.attachments = reportfn
dim key as c = "your_sparkpost_key"
p = email_send_sparkpost(key, ms)
' Update the CRON Job Log table
if p.error = .f. then
a5_updateCRONLog(a5_getprojectguid(), "name_of_cron_job", now(), "success")
else
a5_updateCRONLog(a5_getprojectguid(), "name_of_cron_job", now(), "failed")
end if
%a5See Also